package com.crr.controller;


import com.crr.bean.ProductCategory;
import com.crr.common.bean.ResultBean;
import com.crr.common.controller.BaseController;
import com.crr.service.ProductCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/v1")
@Api(tags = "产品分类")
public class ProductCategoryController extends BaseController {
    @Autowired
    ProductCategoryService productCategoryService;

    @ApiOperation("查询所有子分类")
    @GetMapping("/product/category")
    public ResultBean queryAll() {
        List<Map> list = productCategoryService.queryAll();
        return success("产品分类列表", list);
    }

    @ApiOperation("新增产品类别")
    @PostMapping("/product/category")
    public ResultBean save(@RequestBody ProductCategory productCategory) {
        int res = productCategoryService.save(productCategory);
        return saveResult(res);
    }

    @ApiOperation("删除产品类别")
    @DeleteMapping("/product/category")
    public ResultBean delete(@RequestParam(value = "id", required = true) int id) {
        int res = productCategoryService.delete(id);
        return deleteResult(res);
    }
    @ApiOperation("修改产品类别")
    @PutMapping("/product/category")
    public ResultBean update(@RequestBody ProductCategory productCategory) {
        int res = productCategoryService.update(productCategory);
        return updateResult(res);

    }


}
